//
//  BannerVC.m
//  CJModileAdDemo
//
//  Created by CJ on 2022/3/7.
//

#import "BannerVC.h"
#import <CJMobileAd/CJMobileAd.h>
#import "CustomShowView.h"
#import <WindMillSDK/WindMillBannerView.h>
#import <WindMillSDK/WindMillAdRequest.h>

@interface BannerVC ()<WindMillBannerViewDelegate>

@property (nonatomic, strong) WindMillBannerView *bannerView;

@property (nonatomic, strong) UIView *bannerRealView;

@end

@implementation BannerVC

@synthesize customView = _customView;
    
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)dealloc
{
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)setupUI {
    self.title = @"Banner";
    [self.view addSubview:self.customView];
    self.customView.frame = CGRectMake(0, 100, 200, 200);
    self.customView.center = self.view.center;
}

- (void)loadAdData {
    WindMillAdRequest *request = [WindMillAdRequest request];
    request.userId = @"user_id";
    request.placementId = @"2358674157473912";
    request.options = @{@"test_key":@"test_value", @"ad_width": @([UIScreen mainScreen].bounds.size.width)};//s2s激励时自定义参数，key和value都是媒体开发自定义
    WindMillBannerView *bannerView = [[WindMillBannerView alloc] initWithRequest:request];
    bannerView.delegate = self;
    bannerView.viewController = self;
    [bannerView loadAdData];
    self.bannerView = bannerView;
}

- (void)handleEvent:(NSInteger)eve {
    if (eve == 0) {
        [self loadAdData];
        return;
    }
}

- (CustomShowView *)customView {
    if (!_customView) {
        _customView = [[CustomShowView alloc] init];
        __weak BannerVC *weakSelf = self;
        _customView.event = ^(NSInteger eve) {
            [weakSelf handleEvent:eve];
        };
    }
    return _customView;
}

#pragma mark CJBannerAdDelegate

- (void)bannerAdViewDidAutoRefresh:(WindMillBannerView *)bannerAdView {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)bannerAdViewLoadSuccess:(WindMillBannerView *)bannerAdView {
    CGSize adSize = bannerAdView.adSize;
    bannerAdView.frame = CGRectMake(0, 120, adSize.width, adSize.height);
    bannerAdView.backgroundColor = [UIColor redColor];
    [self.view addSubview:bannerAdView];
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)bannerAdViewFailedToLoad:(WindMillBannerView *)bannerAdView
                           error:(NSError *)error {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)bannerAdViewWillExpose:(WindMillBannerView *)bannerAdView {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)bannerAdViewDidClicked:(WindMillBannerView *)bannerAdView {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)bannerAdViewDidRemoved:(WindMillBannerView *)bannerAdView {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)bannerAdView:(WindMillBannerView *)bannerAdView didFinishBidADSource:(WindMillAdInfo *)adInfo {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)bannerAdView:(WindMillBannerView *)bannerAdView didFailBidADSource:(WindMillAdInfo *)adInfo error:(NSError *)error {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)bannerAdView:(WindMillBannerView *)bannerAdView didFailToLoadADSource:(WindMillAdInfo *)adInfo error:(NSError *)error {
    NSLog(@"事件:%s", __FUNCTION__);
}

@end
